package com.zlk.algorithm.huawei.leetcode.binaryTree;

import com.zlk.algorithm.util.TreeNode;

/**
 * @program: algorithm
 * @ClassName Code30_kthSmallest
 * @description:
 * @author: slfang
 * @create: 2025-01-09 16:39
 * @Version 1.0
 **/
public class Code30_kthSmallest {


    int count=0 ;
    int ans = -1;
    public int kthSmallest(TreeNode root, int k) {
        midDp(root,k);
        return ans;
    }

    private void midDp(TreeNode root, int k) {
        if(root==null){
            return ;
        }
        midDp(root.left,k);
        count++;
        if(count==k){
            ans = root.val;
        }
        midDp(root.right,k);
    }
}
